import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

public class MenuPanel extends JPanel implements ActionListener {
    private Icon bgSave = Util.getIcon("/images/buttonSave.jpg");
    private Icon bgGet = Util.getIcon("/images/buttonGet.jpg");
    private Icon bgFind = Util.getIcon("/images/buttonFind.jpg");
    private Icon bgOff = Util.getIcon("/images/buttonOff.jpg");
    private Icon bgChan = Util.getIcon("/images/buttonModify.jpg");
    private ATM frame;
    private JButton offButton = new JButton(bgOff);
    private JButton saveButton = new JButton(bgSave);
    private JButton getButton = new JButton(bgGet);
    private JButton findButton = new JButton(bgFind);
    private JButton chanButton=new JButton(bgChan);
    private JButton tranButton=new JButton("转账");

    public MenuPanel(ATM frame) {
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);
        saveButton.setBounds(0, 300, 100, 50);
        getButton.setBounds(0, 400, 100, 50);
        chanButton.setBounds(0,500,100,50);
        findButton.setBounds(910, 300, 100, 50);
        offButton.setBounds(910, 400, 100, 50);
        tranButton.setBounds(910,500,100,50);
        this.add(saveButton);
        this.add(getButton);
        this.add(findButton);
        this.add(offButton);
        this.add(chanButton);
        this.add(tranButton);
        chanButton.addActionListener(this);
        tranButton.addActionListener(this);
        saveButton.addActionListener(this);
        getButton.addActionListener(this);
        findButton.addActionListener(this);
        offButton.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (offButton == e.getSource()) {
            frame.getLoginPanel().setAcount(0);
            frame.switchPanel("login");
        } else if (saveButton == e.getSource()) {
            frame.switchPanel("save");
        } else if (getButton == e.getSource()) {
            frame.switchPanel("get");
        } else if (findButton == e.getSource()) {
            String str = "";
            str = "余额为：" + frame.getList().get(frame.getLoginPanel().getIndex()).getMoney();
            frame.getFindPanell().getjLabel().setText(str);
            frame.switchPanel("find");
        }else if (chanButton==e.getSource()){
            frame.switchPanel("gaimi");
        }else if (tranButton==e.getSource()){
            frame.switchPanel("zhuan");
        }
    }
}
